package com.cp.core.controller.admin;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cp.base.util.JwtUtils;
import com.cp.common.result.R;
import com.cp.core.pojo.entity.Borrower;
import com.cp.core.pojo.vo.BorrowerApprovalVO;
import com.cp.core.pojo.vo.BorrowerDetailVO;
import com.cp.core.pojo.vo.BorrowerVo;
import com.cp.core.service.BorrowerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author ming
 * @since 2022-07-27
 */
@RestController
@RequestMapping("/admin/core/borrower")
@Slf4j
@Api(tags = "借款人后台操作")
public class AdminBorrowerController {
    @Resource
    private BorrowerService borrowerService;
    @ApiOperation("获取借款人分页列表")
    @GetMapping("/list/{page}/{limit}")
    public R listPage(
            @ApiParam(value = "当前页码",required = true) @PathVariable Long page,
            @ApiParam(value = "每页显示记录树",required = true) @PathVariable Long limit,
            String keyWord)
    {
        Page<Borrower> pageParam =new Page(page,limit);
        IPage<Borrower> pageModel = borrowerService.listPage(pageParam, keyWord);
        return R.ok().data("pageModel",pageModel);
    }
    @ApiOperation("获取借款人信息")
    @GetMapping("/show/{id}")
    public R show(@ApiParam(value = "借款id",required = true)@PathVariable("id") Long id){
      BorrowerDetailVO borrowerDetailVO = borrowerService.getBorrowerDetailVoById(id);
      return R.ok().data("borrowerDetailVO",borrowerDetailVO);
    }
    @ApiOperation("借款额度审批")
    @PostMapping("/approval")
    public R approval(@RequestBody BorrowerApprovalVO borrowerApprovalVO){
        borrowerService.approval(borrowerApprovalVO);
        return R.ok().message("审批完成");
    }


}

